\documentclass[E:/GsjzTle/main/main.tex]{subfiles}
\begin{document}

\begin{lstlisting}
const int N = 3e2 + 10 , mod = 1e9 + 7;
ll a[N][N];
ll pow_mod(ll x , ll n , ll mod)
{
	ll res = 1;
	while(n)
	{
		if(n & 1) res = res * x % mod;
		x = x * x % mod;
		n >>= 1;
	}
	return res;
}
ll Gauss(int n)
{
	ll ans = 1;
	for(int i = 2 ; i <= n ; i ++)
	{
		for(int j = i + 1 ; j <= n ; j ++) if(!a[i][i] && a[j][i])
		{
			ans = -ans;
			swap(a[i] , a[j]);
			break;
		}
		ll inv = pow_mod(a[i][i] , mod - 2 , mod);
		for(int j = i + 1 ; j <= n ; j ++)
		{
			ll temp = a[j][i] * inv % mod;
			for(int k = i ; k <= n ; k ++) a[j][k] = (a[j][k] - a[i][k] * temp % mod + mod) % mod;
		}
		ans = ans * a[i][i] % mod;
	}
	return ans;
}
signed main()
{
	int n , m , op;
	//op = 0 ÎÞÏòÍ¼ , op = 1ÓÐÏòÍ¼ 
	cin >> n >> m >> op;
	for(int i = 1 ; i <= m ; i ++)
	{
		int u , v , w;
		cin >> u >> v >> w;
		if(!op)
		{
			a[u][u] = (a[u][u] + w) % mod;
			a[v][v] = (a[v][v] + w) % mod;
			a[u][v] = (a[u][v] - w + mod) % mod;
			a[v][u] = (a[v][u] - w + mod) % mod;
		}
		else
		{
			a[v][v] = (a[v][v] + w) % mod;
			a[u][v] = (a[u][v] - w + mod) % mod;
		}
	}
	cout << Gauss(n) << '\n';
	return 0;
}
\end{lstlisting}

\end{document}
